home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #1 / Amiga Plus CD - 2000 - No. 1.iso / Tools / Dev / mamesrc / src / amiga / gui_mui.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-03  |  56.2 KB  |  1,839 lines

  1. /**************************************************************************
  2.  *
  3.  * Copyright (C) 1999 Mats Eirik Hansen (mats.hansen@triumph.no)
  4.  *
  5.  * $Id: gui_mui.c,v 1.2 1999/05/13 13:51:02 meh Exp meh $
  6.  *
  7.  * $Log: gui_mui.c,v $
  8.  * Revision 1.2  1999/05/13 13:51:02  meh
  9.  * *** empty log message ***
  10.  *
  11.  * Revision 1.1  1999/04/28 18:54:28  meh
  12.  * Initial revision
  13.  *
  14.  *
  15.  *************************************************************************/
  16.  
  17. #include <ctype.h>
  18.  
  19. #include <clib/alib_protos.h>
  20.  
  21. #include <exec/types.h>
  22. #include <dos/dosextens.h>
  23. #include <libraries/mui.h>
  24. #include <libraries/iffparse.h>
  25. #include <libraries/gadtools.h>
  26. #include <libraries/asl.h>
  27.  
  28. #include <inline/exec.h>
  29. #include <inline/dos.h>
  30. #include <inline/graphics.h>
  31. #include <inline/intuition.h>
  32. #include <inline/muimaster.h>
  33. #include <inline/utility.h>
  34. #include <inline/keymap.h>
  35.  
  36. #include "main.h"
  37. #include "driver.h"
  38. #include "gui.h"
  39. #include "config.h"
  40. #include "version.h"
  41.  
  42. #define RID_Start      1
  43. #define RID_CloseAbout 2
  44. #define RID_Scan       3
  45.  
  46. #define MID_About     104
  47. #define MID_AboutMUI  105
  48.  
  49. #define SMT_DISPLAYID 0
  50. #define SMT_DEPTH     1
  51.  
  52. #ifdef MESS
  53. #define DRIVER_OFFSET 0
  54.  
  55. #define TEXT_ABOUT \
  56. "\33c\n\33b\33uMESS - Multi-Emulator Super System\33n\n\n" \
  57. "0."REVISION" ("REVDATE")\n\n" \
  58. "Copyright (C) 1998 by the MESS team\n" \
  59. "http://www.internetter.com/titan/mess\n\n" \
  60. "Amiga port by Mats Eirik Hansen\n" \
  61. "http://www.triumph.no/mess\n" \
  62. "CGXHooks routines by Trond Werner Hansen\n\n" \
  63. "Chunky to planar routine by Mikael Kalms\n\n" \
  64. "This program uses MUI - Magic User Interface\n" \
  65. "MUI is © 1992 - 1997 by Stefan Stuntz\n" \
  66. "http://www.sasg.com"
  67. #else
  68. #define DRIVER_OFFSET 2
  69.  
  70. #define TEXT_ABOUT \
  71. "\33c\n\33b\33uMAME - Multiple Arcade Machine Emulator\33n\n\n" \
  72. "0."REVISION" ("REVDATE")\n\n" \
  73. "Copyright (C) 1997-1999 by Nicola Salmoria and the MAME team\n" \
  74. "http://www.media.dsi.unimi.it/mame\n\n" \
  75. "Amiga port by Mats Eirik Hansen\n" \
  76. "http://www.triumph.no/mame\n" \
  77. "CGXHooks routines by Trond Werner Hansen\n\n" \
  78. "Chunky to planar routine by Mikael Kalms\n\n" \
  79. "This program uses MUI - Magic User Interface\n" \
  80. "MUI is © 1992 - 1997 by Stefan Stuntz\n" \
  81. "http://www.sasg.com"
  82. #endif
  83.  
  84. struct DriverData
  85. {
  86.   struct MUI_EventHandlerNode EventHandler;
  87.   ULONG           CurrentEntry;
  88.   ULONG           CharIndex;
  89.   ULONG           Seconds;
  90.   ULONG           Micros;
  91.   APTR            List;
  92. };
  93.  
  94. extern struct Library *KeymapBase;
  95.  
  96. struct Library *MUIMasterBase = NULL;
  97.  
  98. static struct GameDriver ***SortedDrivers = NULL;
  99.  
  100. static char  *DriversFound = NULL;
  101. static ULONG NumDrivers;
  102.  
  103. static struct MUI_CustomClass *DriverClass;
  104.  
  105. static APTR App;
  106. static APTR MainWin;
  107. static APTR AboutWin;
  108. static APTR DisplayName;
  109.  
  110. static APTR RE_Options;
  111. static APTR CM_Allow16Bit;
  112. static APTR CM_FlipX;
  113. static APTR CM_FlipY;
  114. static APTR CM_DirtyLines;
  115. static APTR CM_AutoFrameSkip;
  116. #ifndef MESS
  117. static APTR CY_Show;
  118. static APTR CM_UseDefaults;
  119. static APTR BU_Scan;
  120. #endif
  121. static APTR CM_Antialiasing;
  122. static APTR CM_Translucency;
  123. static APTR SL_BeamWidth;
  124. static APTR SL_VectorFlicker;
  125. static APTR SL_AudioChannel[4];
  126. static APTR SL_MinFreeChip;
  127. static APTR SL_FrameSkip;
  128. static APTR SL_Joy1ButtonBTime;
  129. static APTR SL_Joy1AutoFireRate;
  130. static APTR SL_Joy2ButtonBTime;
  131. static APTR SL_Joy2AutoFireRate;
  132. static APTR ST_Width;
  133. static APTR ST_Height;
  134. static APTR ST_RomPath;
  135. static APTR ST_SamplePath;
  136. static APTR CY_ScreenType;
  137. static APTR CY_DirectMode;
  138. static APTR CY_Sound;
  139. static APTR CY_Buffering;
  140. static APTR CY_Rotation;
  141. static APTR CY_Joy1Type;
  142. static APTR CY_Joy2Type;
  143. static APTR PA_ScreenMode;
  144. static APTR PA_RomPath;
  145. static APTR PA_SamplePath;
  146. static APTR LI_Driver;
  147. static APTR LV_Driver;
  148. static APTR BU_Start;
  149. static APTR BU_Quit;
  150. static APTR BU_About_OK;
  151. static APTR PU_ScreenMode;
  152.  
  153. #ifdef POWERUP
  154. static APTR CM_AsyncPPC;
  155. #endif
  156.  
  157. static struct NameInfo DisplayNameInfo;
  158. static UBYTE           DisplayNameBuffer[256];
  159.  
  160. static STRPTR Shows[] =
  161. {
  162.   (STRPTR) MSG_ALL,
  163.   (STRPTR) MSG_FOUND,
  164.   NULL
  165. };
  166.  
  167. static STRPTR ScreenTypes[] =
  168. {
  169.   (STRPTR) MSG_BEST,
  170.   (STRPTR) MSG_WORKBENCH,
  171.   (STRPTR) MSG_CUSTOM,
  172.   (STRPTR) MSG_USER_SELECT,
  173.   NULL
  174. };
  175.  
  176. static APTR DirectModes[] =
  177. {
  178.   (STRPTR) MSG_OFF,
  179.   (STRPTR) MSG_DRAW,
  180.   (STRPTR) MSG_COPY,
  181.   NULL
  182. };
  183.  
  184. static STRPTR Sounds[] =
  185. {
  186.   (STRPTR) MSG_NONE,
  187.   (STRPTR) MSG_PAULA,
  188.   (STRPTR) MSG_AHI,
  189.   NULL
  190. };
  191.  
  192. static STRPTR Joy1Types[] =
  193. {
  194.   (STRPTR) MSG_NONE,
  195.   (STRPTR) MSG_JOYSTICK_PORT_2,
  196.   (STRPTR) MSG_JOYPAD_PORT_2,
  197.   (STRPTR) MSG_MOUSE_PORT_1,
  198.   NULL
  199. };
  200.  
  201. static STRPTR Joy2Types[] =
  202. {
  203.   (STRPTR) MSG_NONE,
  204.   (STRPTR) MSG_JOYSTICK_PORT_1,
  205.   (STRPTR) MSG_JOYPAD_PORT_1,
  206.   NULL
  207. };
  208.  
  209. static STRPTR Rotations[] =
  210. {
  211.   (STRPTR) MSG_NO,
  212.   (STRPTR) MSG_LEFT,
  213.   (STRPTR) MSG_RIGHT,
  214.   NULL
  215. };
  216.  
  217. static STRPTR RegisterTitles[] =
  218. {
  219.   (STRPTR) MSG_DRIVERS,
  220.   (STRPTR) MSG_DISPLAY,
  221.   (STRPTR) MSG_SOUND,
  222.   (STRPTR) MSG_INPUT,
  223.   (STRPTR) MSG_PATHS,
  224.   NULL
  225. };
  226.  
  227. static STRPTR Bufferings[] =
  228. {
  229.   (STRPTR) MSG_SINGLE,
  230.   (STRPTR) MSG_DOUBLE,
  231.   (STRPTR) MSG_TRIPLE,
  232.   NULL
  233. };
  234.  
  235. static struct TagItem ScreenModeTags[] =
  236. {
  237.   { ASLSM_InitialDisplayID,   0 },
  238.   { ASLSM_InitialDisplayDepth,  8 },
  239.   { ASLSM_DoDepth,        TRUE  },
  240.   { TAG_END }
  241. };
  242.  
  243. static struct Hook ScreenModeStartHook;
  244. static struct Hook ScreenModeStopHook;
  245. static struct Hook ScreenTypeNotifyHook;
  246. static struct Hook DirectModeNotifyHook;
  247. static struct Hook SoundNotifyHook;
  248. static struct Hook DriverDisplayHook;
  249. static struct Hook DriverNotifyHook;
  250. #ifndef MESS
  251. static struct Hook ShowNotifyHook;
  252. static struct Hook UseDefaultsNotifyHook;
  253. #endif
  254.  
  255. #ifndef MESS
  256. static char *DriverString;
  257. static char *DirectoryString;
  258. static char *TypeString;
  259. static char *WidthString;
  260. static char *HeightString;
  261. static char *ColorsString;
  262. static char *CommentString;
  263. static char *NotWorkingString;
  264. static char *WrongColorsString;
  265. static char *ImperfectColorsString;
  266. static char *BitmapString;
  267. static char *VectorString;
  268. static char *BitmapGameDefaultsString;
  269. static char *VectorGameDefaultsString;
  270. #endif
  271.  
  272. static void CreateApp(void);
  273. static void GetOptions(BOOL get_driver);
  274. static void SetOptions(BOOL set_driver);
  275. static void SetDisplayName(ULONG);
  276. static ULONG ASM ScreenModeStart(struct Hook *hook REG(a0), APTR popasl REG(a2), struct TagItem *taglist REG(a1));
  277. static ULONG ASM ScreenModeStop(struct Hook *hook REG(a0), APTR popasl REG(a2), struct ScreenModeRequester *smreq REG(a1));
  278. static ULONG ASM ScreenTypeNotify(struct Hook *hook REG(a0), APTR obj REG(a2), ULONG *par REG(a1));
  279. static ULONG ASM DirectModeNotify(struct Hook *hook REG(a0), APTR obj REG(a2), ULONG *par REG(a1));
  280. static ULONG ASM SoundNotify(struct Hook *hook REG(a0), APTR obj REG(a2), ULONG *par REG(a1));
  281. static ULONG ASM DriverNotify(struct Hook *hook REG(a0), APTR obj REG(a2), ULONG *par REG(a1));
  282. #ifndef MESS
  283. static ULONG ASM ShowNotify(struct Hook *hook REG(a0), APTR obj REG(a2), ULONG *par REG(a1));
  284. static ULONG ASM UseDefaultsNotify(struct Hook *hook REG(a0), APTR obj REG(a2), ULONG *par REG(a1));
  285. #endif
  286.  
  287. /* Convert an index in SortedDrivers into an index for the same
  288.  * driver in Drivers. */
  289.  
  290. static inline int GetSortedDriverIndex(int sorted_index)
  291. {
  292.   int index;
  293.  
  294.   if(sorted_index < DRIVER_OFFSET)
  295.     index = sorted_index - DRIVER_OFFSET;
  296.   else
  297.     index = (((ULONG) SortedDrivers[sorted_index]) - ((ULONG) &Drivers[0])) / sizeof(struct GameDriver *);
  298.  
  299.   return(index);
  300. }
  301.  
  302. static inline int GetEntryDriverIndex(ULONG entry)
  303. {
  304.   int index;
  305.  
  306.   index = (entry - ((ULONG) &Drivers[0])) / sizeof(struct GameDriver *);
  307.   
  308.   return(index);
  309. }
  310.  
  311. static int GetDriverIndex(void)
  312. {
  313.   ULONG entry;
  314.   ULONG list_index;
  315.   int   index;
  316.  
  317.   get(LI_Driver, MUIA_List_Active, &list_index);
  318.  
  319.   if(list_index == MUIV_List_Active_Off)
  320.   {
  321.     index = -DRIVER_OFFSET - 1;
  322.   }
  323.   else if(list_index < DRIVER_OFFSET)
  324.   {
  325.     index = list_index - DRIVER_OFFSET;
  326.   }
  327.   else
  328.   {
  329.     DoMethod(LI_Driver, MUIM_List_GetEntry, list_index, &entry);
  330.  
  331.     index = GetEntryDriverIndex(entry);
  332.   }
  333.  
  334.   return(index);
  335. }
  336.  
  337. static struct GameDriver *GetDriver(void)
  338. {
  339.   struct GameDriver *drv;
  340.  
  341.   ULONG entry;
  342.   ULONG list_index;
  343.  
  344.   get(LI_Driver, MUIA_List_Active, &list_index);
  345.  
  346.   if((list_index == MUIV_List_Active_Off) || (list_index < DRIVER_OFFSET))
  347.     return(NULL);
  348.  
  349.   DoMethod(LI_Driver, MUIM_List_GetEntry, list_index, &entry);
  350.  
  351.   if(!entry)
  352.     return(NULL);
  353.  
  354.   drv = *((struct GameDriver **) entry);
  355.  
  356.   return(drv);
  357. }
  358.  
  359. #ifndef MESS
  360. static void ScanDrivers(void)
  361. {
  362.   struct FileInfoBlock *fib;
  363.   const char           *str;
  364.  
  365.   BPTR locks[4];
  366.   LONG i, j, len;
  367.   char buf[13];    /* 8.3 filename. */
  368.   int  bitmap_lock;
  369.   int  vector_lock;
  370.  
  371.   if(DriversFound)
  372.   {
  373.     memset(DriversFound, 0, NumDrivers);
  374.   
  375.     fib = AllocDosObject(DOS_FIB, NULL);
  376.  
  377.     if(fib)
  378.     {
  379.       bitmap_lock = -1;
  380.       vector_lock = -1;
  381.  
  382.       j = 0;
  383.  
  384.       locks[j++] = DupLock(((struct Process *) FindTask(NULL))->pr_CurrentDir);
  385.  
  386.       locks[j++] = Lock("roms", ACCESS_READ);
  387.  
  388.       str = GetRomPath(0, 0);
  389.  
  390.       if(str)
  391.       {
  392.         if(str[0])
  393.         {
  394.           locks[j] = Lock((STRPTR) str, ACCESS_READ);
  395.  
  396.           if(locks[j])
  397.           {
  398.             if( (SameLock(locks[0], locks[j]) == LOCK_SAME)
  399.             ||  (SameLock(locks[1], locks[j]) == LOCK_SAME))
  400.               UnLock(locks[j]);
  401.             else
  402.               bitmap_lock = j++;
  403.           }
  404.         }
  405.       }
  406.  
  407.       str = GetRomPath(1, 0);
  408.  
  409.       if(str)
  410.       {
  411.         if(strlen(str))
  412.         {
  413.           locks[j] = Lock((STRPTR) str, ACCESS_READ);
  414.  
  415.           if(locks[j])
  416.           {
  417.             if( (SameLock(locks[0], locks[j]) == LOCK_SAME)
  418.             ||  (SameLock(locks[1], locks[j]) == LOCK_SAME))
  419.               UnLock(locks[j]);
  420.             else
  421.               vector_lock = j++;
  422.           }
  423.         }
  424.       }
  425.  
  426.       for(; --j >= 0;)
  427.       {
  428.         if(Examine(locks[j], fib))
  429.         {
  430.           if(fib->fib_DirEntryType > 0)
  431.           {
  432.             while(ExNext(locks[j], fib))
  433.             {
  434.               for(i = 0; i < NumDrivers; i++)
  435.               {
  436.                 if( !DriversFound[i]
  437.                 &&  ((j != bitmap_lock) || !((*SortedDrivers[i+DRIVER_OFFSET])->drv->video_attributes & VIDEO_TYPE_VECTOR))
  438.                 &&  ((j != vector_lock) || ((*SortedDrivers[i+DRIVER_OFFSET])->drv->video_attributes & VIDEO_TYPE_VECTOR)))
  439.                 {
  440.                   len = strlen((*SortedDrivers[i+DRIVER_OFFSET])->name);
  441.  
  442.                   if(!strnicmp(fib->fib_FileName, (*SortedDrivers[i+DRIVER_OFFSET])->name, len))
  443.                   {
  444.                     if(!fib->fib_FileName[len])
  445.                     {
  446.                       if(fib->fib_DirEntryType > 0)
  447.                       {
  448.                         DriversFound[i] = 1;
  449.                         break;
  450.                       }
  451.                     }
  452.                     else if(fib->fib_DirEntryType < 0)
  453.                     {
  454.                       if( !stricmp(&fib->fib_FileName[len], ".zip")
  455.                       ||  !stricmp(&fib->fib_FileName[len], ".lha")
  456.                       ||  !stricmp(&fib->fib_FileName[len], ".lzx"))
  457.                       {
  458.                         DriversFound[i] = 1;
  459.                         break;
  460.                       }
  461.                     }
  462.                   }
  463.                 }
  464.               }
  465.             }
  466.           }
  467.         }
  468.         
  469.         if(locks[j])
  470.           UnLock(locks[j]);
  471.       }
  472.     }
  473.     
  474.     /* The code above searched in current dir, roms/ and any the rom path specified for
  475.      * the bitmap and vector driver defaults. Now I'll look for any driver that has its
  476.      * own rom path. */
  477.     
  478.     for(i = 0; i < NumDrivers; i++)
  479.     {
  480.       if(!DriversFound[i])
  481.       {
  482.         if(!GetUseDefaults(GetSortedDriverIndex(DRIVER_OFFSET+i)))
  483.         {
  484.           str = GetRomPath(GetSortedDriverIndex(DRIVER_OFFSET+i), 0);
  485.           
  486.           if(str && strlen(str))
  487.           {
  488.             locks[0] = Lock((STRPTR) str, ACCESS_READ);
  489.             
  490.             if(locks[0])
  491.             {
  492.               locks[1] = CurrentDir(locks[0]);
  493.             
  494.               locks[2] = Lock((char *) (*SortedDrivers[i+DRIVER_OFFSET])->name, ACCESS_READ);
  495.             
  496.               if(!locks[2])
  497.               {
  498.                 sprintf(buf, "%s.zip", (*SortedDrivers[i+DRIVER_OFFSET])->name);
  499.                 locks[2] = Lock(buf, ACCESS_READ);
  500.  
  501.                 if(!locks[2])
  502.                 {
  503.                   sprintf(buf, "%s.lha", (*SortedDrivers[i+DRIVER_OFFSET])->name);
  504.                   locks[2] = Lock(buf, ACCESS_READ);          
  505.  
  506.                   if(!locks[2])
  507.                   {
  508.                     sprintf(buf, "%s.lzx", (*SortedDrivers[i+DRIVER_OFFSET])->name);
  509.                     locks[2] = Lock(buf, ACCESS_READ);          
  510.                   }
  511.                 }
  512.               }
  513.               
  514.               if(locks[2])
  515.               {
  516.                 UnLock(locks[2]);
  517.   
  518.                 DriversFound[i] = 1;
  519.               }
  520.               
  521.               CurrentDir(locks[1]);
  522.               UnLock(locks[0]);
  523.             }
  524.           }
  525.         }
  526.       }
  527.     }
  528.  
  529.     for(i = 0; i < NumDrivers; i++)
  530.       SetFound(DRIVER_OFFSET+GetSortedDriverIndex(DRIVER_OFFSET+i),DriversFound[i]);
  531.   }
  532. }
  533.  
  534. static void ShowFound(void)
  535. {
  536.   int start;
  537.   int end;
  538.   int num;
  539.   int max;
  540.  
  541.   start = 0;
  542.   end   = DRIVER_OFFSET;
  543.   max   = NumDrivers + DRIVER_OFFSET;
  544.  
  545.   while(start < max)
  546.   {
  547.     for(; (end < max) && GetFound(DRIVER_OFFSET+GetSortedDriverIndex(end)); end++);
  548.     
  549.     num = end - start;
  550.  
  551.     if(num > 0)
  552.       DoMethod(LI_Driver, MUIM_List_Insert, &SortedDrivers[start], num, MUIV_List_Insert_Bottom);
  553.  
  554.     for(; (end < max) && !GetFound(DRIVER_OFFSET+GetSortedDriverIndex(end)); end++);
  555.  
  556.     start = end;
  557.  
  558.     end++;
  559.   }
  560. }
  561. #endif
  562.  
  563. static int DriverCompare(struct GameDriver ***drv1, struct GameDriver ***drv2)
  564. {
  565.   return(stricmp((**drv1)->description, (**drv2)->description));
  566. }
  567.  
  568. static ULONG ASM DriverDisplay(struct Hook *hook REG(a0), char **array REG(a2), struct GameDriver **drv_indirect REG(a1))
  569. {
  570.   struct GameDriver *drv;
  571.  
  572. #ifdef MESS
  573.   *array++ = (char *) drv->description;
  574. #else
  575.   static char driver[55];
  576.   static char directory[55];
  577.   static char type[55];
  578.   static char width[55];
  579.   static char height[55];
  580.   static char colors[55];
  581.   static char comment[105];
  582.  
  583.   if(!drv_indirect)
  584.   {
  585.     sprintf(driver,   "\033b\033u%s", DriverString);
  586.     sprintf(directory,  "\033b\033u%s", DirectoryString);
  587.     sprintf(type,   "\033b\033u%s", TypeString);
  588.     sprintf(width,    "\033b\033u%s", WidthString);
  589.     sprintf(height,   "\033b\033u%s", HeightString);
  590.     sprintf(colors,   "\033b\033u%s", ColorsString);
  591.     sprintf(comment,  "\033b\033u%s", CommentString);
  592.  
  593.     *array++  = driver;
  594.     *array++  = directory;
  595.     *array++  = type;
  596.     *array++  = width;
  597.     *array++  = height;
  598.     *array++  = colors;
  599.     *array++  = comment;
  600.  
  601.     return(0);
  602.   }
  603.  
  604.   if(drv_indirect == (struct GameDriver **) 1)
  605.   {
  606.     sprintf(driver, "\0338%s", BitmapGameDefaultsString);
  607.  
  608.     *array++  = driver;
  609.     *array++  = "";
  610.     *array++  = "";
  611.     *array++  = "";
  612.     *array++  = "";
  613.     *array++  = "";
  614.     *array++  = "";
  615.  
  616.     return(0);
  617.   }
  618.  
  619.   if(drv_indirect == (struct GameDriver **) 2)
  620.   {
  621.     sprintf(driver, "\0338%s", VectorGameDefaultsString);
  622.   
  623.     *array++  = driver;
  624.     *array++  = "";
  625.     *array++  = "";
  626.     *array++  = "";
  627.     *array++  = "";
  628.     *array++  = "";
  629.     *array++  = "";
  630.     
  631.     return(0);
  632.   }
  633.  
  634.   drv = *drv_indirect;
  635.  
  636.   *array++ = (char *) drv->description;
  637.   *array++ = (char *) drv->name;
  638.   
  639.   if(drv->drv->video_attributes & VIDEO_TYPE_VECTOR)
  640.   {
  641.     *array++  = VectorString;
  642.     *array++  = "";
  643.     *array++  = "";
  644.   }
  645.   else
  646.   {
  647.     *array++  = BitmapString;
  648.     if(drv->orientation & ORIENTATION_SWAP_XY)
  649.       sprintf(width, "%d", drv->drv->screen_height);  
  650.     else
  651.       sprintf(width, "%d", drv->drv->screen_width); 
  652.     *array++  = width;
  653.     if(drv->orientation & ORIENTATION_SWAP_XY)
  654.       sprintf(height, "%d", drv->drv->screen_width);  
  655.     else
  656.       sprintf(height, "%d", drv->drv->screen_height); 
  657.     *array++  = height;
  658.   }
  659.  
  660.   if(drv->drv->video_attributes & VIDEO_SUPPORTS_16BIT)
  661.     sprintf(colors, "16Bit");
  662.   else if(drv->drv->total_colors > 256)
  663.     sprintf(colors, "256");
  664.   else
  665.     sprintf(colors, "%d", drv->drv->total_colors);
  666.  
  667.   *array++ = colors;
  668.  
  669.   if(drv->flags & GAME_NOT_WORKING)
  670.     *array++ = NotWorkingString;
  671.   else if(drv->flags & GAME_WRONG_COLORS)
  672.     *array++ = WrongColorsString;
  673.   else if(drv->flags & GAME_IMPERFECT_COLORS)
  674.     *array++ = ImperfectColorsString;
  675.   else
  676.     *array++ = "";
  677. #endif
  678.   return(0);
  679. }
  680.  
  681. static ULONG ASM DriverDispatcher(struct IClass *class REG(a0), APTR obj REG(a2), Msg msg REG(a1))
  682. {
  683.   struct DriverData   *data;
  684.   struct IntuiMessage *imsg;
  685.   struct GameDriver   **drv_indirect;
  686.   struct GameDriver   *drv;
  687.   struct InputEvent   ie;
  688.  
  689.   APTR  list;
  690.   APTR  active_obj;
  691.   ULONG i;
  692.   UBYTE key;
  693.  
  694.   switch(msg->MethodID)
  695.   {
  696.     case MUIM_Setup:
  697.       data = INST_DATA(class, obj);
  698.  
  699.       if(DoSuperMethodA(class, obj, msg))
  700.       {
  701.         data->Seconds = 0;
  702.         data->Micros  = 0;
  703.  
  704.         data->EventHandler.ehn_Priority = 0;
  705.         data->EventHandler.ehn_Flags    = 0;
  706.         data->EventHandler.ehn_Object   = obj;
  707.         data->EventHandler.ehn_Class    = class;
  708.         data->EventHandler.ehn_Events   = IDCMP_RAWKEY;       
  709.         DoMethod(_win(obj), MUIM_Window_AddEventHandler, &data->EventHandler);
  710.  
  711.         return(TRUE);
  712.       }
  713.       
  714.       return(FALSE);
  715.     
  716.     case MUIM_Cleanup:
  717.       data = INST_DATA(class, obj);
  718.  
  719.       DoMethod(_win(obj), MUIM_Window_RemEventHandler, &data->EventHandler);
  720.       break;
  721.  
  722.     case MUIM_HandleEvent:
  723.       data = INST_DATA(class, obj);
  724.       imsg = (struct IntuiMessage *) msg[1].MethodID;
  725.  
  726.       get(_win(obj), MUIA_Window_ActiveObject, &active_obj);
  727.  
  728.       if(obj == active_obj)
  729.       {
  730.         if(imsg->Class == IDCMP_RAWKEY)
  731.         {
  732.           ie.ie_Class   = IECLASS_RAWKEY;
  733.           ie.ie_SubClass  = 0;
  734.           ie.ie_Code    = imsg->Code;
  735.           ie.ie_Qualifier = 0;
  736.         
  737.           if(MapRawKey(&ie, &key, 1, NULL) && isalnum(key))
  738.           {
  739.             i = imsg->Seconds - data->Seconds;
  740.             
  741.             if(imsg->Micros < data->Micros)
  742.               i--;
  743.           
  744.             if(i < 1)
  745.             {
  746.               data->CharIndex++;
  747.               i = data->CurrentEntry;
  748.             }
  749.             else
  750.             {
  751.               data->CharIndex = 0;
  752.               i = DRIVER_OFFSET;
  753.             }
  754.  
  755.             data->Seconds = imsg->Seconds;
  756.             data->Micros  = imsg->Micros;
  757.  
  758.             get(obj, MUIA_Listview_List, &list);
  759.  
  760.             do
  761.             {
  762.               DoMethod(list, MUIM_List_GetEntry, i, &drv_indirect);
  763.               
  764.               if(drv_indirect)
  765.               {
  766.                 drv = *drv_indirect;
  767.               
  768.                 if(data->CharIndex < strlen(drv->description))
  769.                 {
  770.                   if(key <= tolower(drv->description[data->CharIndex]))
  771.                   {
  772.                     data->CurrentEntry = i;
  773.                 
  774.                     set(list, MUIA_List_Active, i);
  775.                 
  776.                     break;
  777.                   }
  778.                 }
  779.               }
  780.  
  781.               i++;
  782.  
  783.             } while(drv_indirect);
  784.  
  785.             return(MUI_EventHandlerRC_Eat);
  786.           }
  787.         }
  788.       }
  789.       
  790.       return(0);
  791.   }
  792.  
  793.   return(DoSuperMethodA(class, obj, msg));
  794. }
  795.  
  796. void AllocGUI(void)
  797. {
  798.   LONG  i;
  799.  
  800.   for(NumDrivers = 0; Drivers[NumDrivers]; NumDrivers++);
  801.     
  802.   SortedDrivers = malloc((NumDrivers + DRIVER_OFFSET) * sizeof(struct GameDriver **));
  803.  
  804.   if(SortedDrivers)
  805.   {
  806. #ifndef MESS
  807.     SortedDrivers[0]  = (struct GameDriver **) 1;
  808.     SortedDrivers[1]  = (struct GameDriver **) 2;
  809. #endif
  810.     for(i = 0; i < NumDrivers; i++)
  811.       SortedDrivers[i+DRIVER_OFFSET] = &Drivers[i];
  812.  
  813.     qsort(&SortedDrivers[DRIVER_OFFSET], NumDrivers, sizeof(struct GameDriver **), (int (*)(const void *, const void *)) DriverCompare);
  814.  
  815.     MUIMasterBase = OpenLibrary("muimaster.library", 16);
  816.  
  817.     DriversFound  = malloc(NumDrivers);
  818.  
  819.     App     = NULL;
  820.     MainWin   = NULL;
  821.     AboutWin  = NULL;
  822.  
  823.     for(i = 0; Shows[i]; i++)
  824.       Shows[i] = GetMessage((LONG) Shows[i]);
  825.  
  826.     for(i = 0; ScreenTypes[i]; i++)
  827.       ScreenTypes[i] = GetMessage((LONG) ScreenTypes[i]);
  828.  
  829.     for(i = 0; DirectModes[i]; i++)
  830.       DirectModes[i] = GetMessage((LONG) DirectModes[i]);
  831.  
  832.     for(i = 0; Sounds[i]; i++)
  833.       Sounds[i] = GetMessage((LONG) Sounds[i]);
  834.  
  835.     for(i = 0; Joy1Types[i]; i++)
  836.       Joy1Types[i] = GetMessage((LONG) Joy1Types[i]);
  837.  
  838.     for(i = 0; Joy2Types[i]; i++)
  839.       Joy2Types[i] = GetMessage((LONG) Joy2Types[i]);
  840.  
  841.     for(i = 0; Rotations[i]; i++)
  842.       Rotations[i] = GetMessage((LONG) Rotations[i]);
  843.  
  844.     for(i = 0; RegisterTitles[i]; i++)
  845.       RegisterTitles[i] = GetMessage((LONG) RegisterTitles[i]);
  846.  
  847.     for(i = 0; Bufferings[i]; i++)
  848.       Bufferings[i] = GetMessage((LONG) Bufferings[i]);
  849.   
  850.     ScreenModeStartHook.h_Entry  = (HOOKFUNC) ScreenModeStart;
  851.     ScreenModeStopHook.h_Entry   = (HOOKFUNC) ScreenModeStop;
  852.     ScreenTypeNotifyHook.h_Entry = (HOOKFUNC) ScreenTypeNotify;
  853.     DirectModeNotifyHook.h_Entry = (HOOKFUNC) DirectModeNotify;
  854.     SoundNotifyHook.h_Entry      = (HOOKFUNC) SoundNotify;
  855.     DriverDisplayHook.h_Entry    = (HOOKFUNC) DriverDisplay;
  856.     DriverNotifyHook.h_Entry     = (HOOKFUNC) DriverNotify;
  857. #ifndef MESS
  858.     ShowNotifyHook.h_Entry        = (HOOKFUNC) ShowNotify;
  859.     UseDefaultsNotifyHook.h_Entry = (HOOKFUNC) UseDefaultsNotify;
  860.  
  861.     DriverString             = GetMessage(MSG_DRIVER);
  862.     DirectoryString          = GetMessage(MSG_DIRECTORY);
  863.     TypeString               = GetMessage(MSG_TYPE);
  864.     WidthString              = GetMessage(MSG_WIDTH);
  865.     HeightString             = GetMessage(MSG_HEIGHT);
  866.     ColorsString             = GetMessage(MSG_COLORS);
  867.     CommentString            = GetMessage(MSG_COMMENT);
  868.     NotWorkingString         = GetMessage(MSG_NOT_WORKING);
  869.     WrongColorsString        = GetMessage(MSG_WRONG_COLORS);
  870.     ImperfectColorsString    = GetMessage(MSG_IMPERFECT_COLORS);
  871.     BitmapString             = GetMessage(MSG_BITMAP);
  872.     VectorString             = GetMessage(MSG_VECTOR);
  873.     BitmapGameDefaultsString = GetMessage(MSG_BITMAP_GAME_DEFAULTS);
  874.     VectorGameDefaultsString = GetMessage(MSG_VECTOR_GAME_DEFAULTS);
  875. #endif
  876.  
  877.     DriverClass = MUI_CreateCustomClass(NULL, MUIC_Listview, NULL, sizeof(struct DriverData), DriverDispatcher);
  878.   }
  879. }
  880.  
  881. void FreeGUI(void)
  882. {
  883.   if(SortedDrivers)
  884.   {
  885.     if(App)
  886.       MUI_DisposeObject(App);
  887.  
  888.     if(DriverClass)
  889.       MUI_DeleteCustomClass(DriverClass);
  890.  
  891.     if(DriversFound)
  892.       free(DriversFound);
  893.  
  894.     if(MUIMasterBase)
  895.       CloseLibrary(MUIMasterBase);
  896.  
  897.     free(SortedDrivers);
  898.  
  899.     SortedDrivers = NULL;
  900.   }
  901. }
  902.  
  903. LONG MainGUI(void)
  904. {
  905.   ULONG rid;
  906.   ULONG v;
  907.   ULONG signals = 0;
  908.   BOOL  loop  = TRUE;
  909.  
  910.   if(MUIMasterBase)
  911.   {
  912.     if(!App)
  913.       CreateApp();
  914.     if(App)
  915.     {
  916.       if(!MainWin)
  917.       {
  918.         MainWin = WindowObject,
  919.           MUIA_Window_Title, APPNAME,
  920.           MUIA_Window_ID   , MAKE_ID('M','A','I','N'),
  921.           MUIA_Window_Menustrip, MenustripObject,
  922.             MUIA_Family_Child, MenuObjectT(GetMessage(MSG_MENU_GAME)),
  923.               MUIA_Family_Child, MenuitemObject,
  924.                 MUIA_Menuitem_Title,  GetMessage(MSG_MENU_ABOUT),
  925.                 MUIA_Menuitem_Shortcut, "?",
  926.                 MUIA_UserData,      MID_About,
  927.               End,
  928.               MUIA_Family_Child, MenuitemObject,
  929.                 MUIA_Menuitem_Title,  "About MUI...",
  930.                 MUIA_UserData,      MID_AboutMUI,
  931.               End,
  932.               MUIA_Family_Child, MenuitemObject,
  933.                 MUIA_Menuitem_Title,  NM_BARLABEL,
  934.               End,
  935.               MUIA_Family_Child, MenuitemObject,
  936.                 MUIA_Menuitem_Title,  GetMessage(MSG_MENU_QUIT),
  937.                 MUIA_Menuitem_Shortcut, "Q",
  938.                 MUIA_UserData,      MUIV_Application_ReturnID_Quit,
  939.               End,
  940.             End,
  941.           End,
  942.           WindowContents, VGroup,
  943.             Child, RE_Options = RegisterGroup(RegisterTitles),
  944.               Child, VGroup,
  945.                 Child,  LV_Driver = (DriverClass)
  946.                   ? NewObject(DriverClass->mcc_Class, NULL, 
  947.                   MUIA_Listview_Input,    TRUE,
  948.                     MUIA_Listview_List,     (ULONG) LI_Driver = ListObject,
  949.                       MUIA_List_Title,    TRUE,
  950.                       MUIA_List_Format,   "BAR,BAR,BAR,BAR,BAR,BAR,",
  951.                       MUIA_List_DisplayHook,  &DriverDisplayHook,
  952.                     InputListFrame,
  953.                   End,
  954.                 TAG_END)
  955.                 : ListviewObject,
  956.                   MUIA_Listview_Input, TRUE,
  957.                     MUIA_Listview_List,  LI_Driver = ListObject,
  958.                       MUIA_List_Title, TRUE,
  959.                       MUIA_List_Format, "BAR,BAR,BAR,BAR,BAR,BAR,",
  960.                       MUIA_List_DisplayHook,  &DriverDisplayHook,
  961.                     InputListFrame,
  962.                   End,                
  963.                 End,
  964. #ifndef MESS
  965.                 Child, HGroup,
  966.                   Child, Label(GetMessage(MSG_USE_DEFAULTS)),
  967.                   Child, CM_UseDefaults = CheckMark(Config[CFG_USEDEFAULTS]),
  968.                   Child, Label(GetMessage(MSG_SHOW)),
  969.                   Child, CY_Show = CycleObject,
  970.                     MUIA_Cycle_Entries, (ULONG) Shows,
  971.                   End,
  972.                   Child, BU_Scan = SimpleButton(GetMessage(MSG_SCAN)),
  973.                 End,
  974. #endif
  975.               End,
  976.               Child, VGroup,
  977.                 Child, HVSpace,
  978.                 Child, HGroup,
  979.                   Child, HSpace(0),
  980.                   Child, ColGroup(4),
  981.                     MUIA_HorizWeight, 1000,
  982.                     Child, Label(GetMessage(MSG_ALLOW16BIT)),
  983.                     Child, CM_Allow16Bit = CheckMark(Config[CFG_ALLOW16BIT]),
  984.                     Child, Label(GetMessage(MSG_AUTO_FRAMESKIP)),
  985.                     Child, CM_AutoFrameSkip = CheckMark(Config[CFG_AUTOFRAMESKIP]),
  986.                     Child, Label(GetMessage(MSG_FLIPX)),
  987.                     Child, CM_FlipX = CheckMark(Config[CFG_FLIPX]),
  988.                     Child, Label(GetMessage(MSG_ANTIALIAS)),
  989.                     Child, CM_Antialiasing = CheckMark(Config[CFG_ANTIALIASING]),
  990.                     Child, Label(GetMessage(MSG_FLIPY)),
  991.                     Child, CM_FlipY = CheckMark(Config[CFG_FLIPY]),
  992.                     Child, Label(GetMessage(MSG_TRANSLUCENCY)),
  993.                     Child, CM_Translucency = CheckMark(Config[CFG_TRANSLUCENCY]),
  994.                     Child, Label(GetMessage(MSG_DIRTY_LINES)),
  995.                     Child, CM_DirtyLines = CheckMark(Config[CFG_DIRTYLINES]),
  996. #ifdef POWERUP
  997.                     Child, Label(GetMessage(MSG_ASYNCPPC)),
  998.                     Child, CM_AsyncPPC = CheckMark(Config[CFG_ASYNCPPC]),
  999. #endif
  1000.                   End,
  1001.                   Child, HSpace(0),
  1002.                 End,
  1003.                 Child, HGroup,
  1004.                   Child, HSpace(0),
  1005.                   Child, ColGroup(2),
  1006.                     MUIA_HorizWeight, 1000,
  1007.                     Child, Label(GetMessage(MSG_BEAM)),
  1008.                     Child, SL_BeamWidth = SliderObject,
  1009.                       MUIA_Slider_Min, 1,
  1010.                       MUIA_Slider_Max, 16,
  1011.                     End,
  1012.                     Child, Label(GetMessage(MSG_FLICKER)),
  1013.                     Child, SL_VectorFlicker = SliderObject,
  1014.                       MUIA_Slider_Min, 0,
  1015.                       MUIA_Slider_Max, 100,
  1016.                     End,
  1017.                     Child, Label(GetMessage(MSG_FRAMESKIP)),
  1018.                     Child, SL_FrameSkip = SliderObject,
  1019.                       MUIA_Slider_Min, 0,
  1020.                       MUIA_Slider_Max, 3,
  1021.                     End,
  1022.                     Child, Label(GetMessage(MSG_WIDTH)),
  1023.                     Child, ST_Width = StringObject,
  1024.                       StringFrame,
  1025.                       MUIA_String_Accept, (ULONG) "0123456789",
  1026.                     End,
  1027.                     Child, Label(GetMessage(MSG_HEIGHT)),
  1028.                     Child, ST_Height = StringObject,
  1029.                       StringFrame,
  1030.                       MUIA_String_Accept, (ULONG) "0123456789",
  1031.                     End,
  1032.                   End,
  1033.                   Child, HSpace(0),
  1034.                 End,
  1035.                 Child, HGroup,
  1036.                   Child, HSpace(0),
  1037.                   Child, ColGroup(2),
  1038.                     MUIA_HorizWeight, 1000,
  1039.                     Child, Label(GetMessage(MSG_SCREEN_TYPE)),
  1040.                     Child, CY_ScreenType = CycleObject,
  1041.                       MUIA_Cycle_Entries, (ULONG) ScreenTypes,
  1042.                     End,
  1043.                     Child, Label(GetMessage(MSG_DIRECT_MODE)),
  1044.                     Child, CY_DirectMode = CycleObject,
  1045.                       MUIA_Cycle_Entries, (ULONG) DirectModes,
  1046.                     End,
  1047.                     Child, Label(GetMessage(MSG_BUFFERING)),
  1048.                     Child, CY_Buffering = CycleObject,
  1049.                       MUIA_Cycle_Entries, (ULONG) Bufferings,
  1050.                     End,
  1051.                     Child, Label(GetMessage(MSG_ROTATION)),
  1052.                     Child, CY_Rotation = CycleObject,
  1053.                       MUIA_Cycle_Entries, (ULONG) Rotations,
  1054.                     End,
  1055.                   End,
  1056.                   Child, HSpace(0),
  1057.                 End,
  1058.                 Child, HGroup,
  1059.                   Child, HSpace(0),
  1060.                   Child, ColGroup(2),
  1061.                     MUIA_HorizWeight, 1000,
  1062.                     Child, Label(GetMessage(MSG_SCREENMODE)),
  1063.                     Child, PA_ScreenMode = PopaslObject,
  1064.                       MUIA_Popstring_String,  DisplayName = TextObject,
  1065.                         TextFrame,
  1066.                         MUIA_Background, MUII_TextBack,
  1067.                       End,
  1068.                       MUIA_Popstring_Button,  PU_ScreenMode = PopButton(MUII_PopUp),
  1069.                       MUIA_Popasl_Type,     ASL_ScreenModeRequest,
  1070.                       MUIA_Popasl_StartHook,  (ULONG) &ScreenModeStartHook,
  1071.                       MUIA_Popasl_StopHook, (ULONG) &ScreenModeStopHook,
  1072.                       MUIA_Disabled,      (Config[CFG_SCREENTYPE] != CFGST_CUSTOM),
  1073.                     End,
  1074.                   End,
  1075.                   Child, HSpace(0),
  1076.                 End,
  1077.                 Child, HVSpace,
  1078.               End,
  1079.               Child, VGroup,
  1080.                 Child, HVSpace,
  1081.                 Child, HGroup,
  1082.                   Child, HSpace(0),
  1083.                   Child, ColGroup(4),
  1084.                     MUIA_HorizWeight, 1000,
  1085.                     Child, Label(GetMessage(MSG_SOUND)),
  1086.                     Child, CY_Sound =  CycleObject,
  1087.                       MUIA_Cycle_Entries, (ULONG) Sounds,
  1088.                     End,
  1089.                   End,
  1090.                   Child, HSpace(0),
  1091.                 End,
  1092.                 Child, HGroup,
  1093.                   Child, RectangleObject, End,
  1094.                   Child, ColGroup(2),
  1095.                     MUIA_HorizWeight, 1000,
  1096.                     Child, Label(GetMessage(MSG_AUDIO_CH_0)),
  1097.                     Child, SL_AudioChannel[0] = SliderObject,
  1098.                       MUIA_Slider_Min,    0,
  1099.                       MUIA_Slider_Max,    15,
  1100.                     End,
  1101.                     Child, Label(GetMessage(MSG_AUDIO_CH_1)),
  1102.                     Child, SL_AudioChannel[1] = SliderObject,
  1103.                       MUIA_Slider_Min,    0,
  1104.                       MUIA_Slider_Max,    15,
  1105.                     End,
  1106.                     Child, Label(GetMessage(MSG_AUDIO_CH_2)),
  1107.                     Child, SL_AudioChannel[2] = SliderObject,
  1108.                       MUIA_Slider_Min,    0,
  1109.                       MUIA_Slider_Max,    15,
  1110.                     End,
  1111.                     Child, Label(GetMessage(MSG_AUDIO_CH_3)),
  1112.                     Child, SL_AudioChannel[3] = SliderObject,
  1113.                       MUIA_Slider_Min,    0,
  1114.                       MUIA_Slider_Max,    15,
  1115.                     End,
  1116.                     Child, Label(GetMessage(MSG_MIN_CHIP)),
  1117.                     Child, SL_MinFreeChip = SliderObject,
  1118.                       MUIA_Slider_Min,    0,
  1119.                       MUIA_Slider_Max,    2048,
  1120.                     End,
  1121.                   End,
  1122.                   Child, RectangleObject, End,
  1123.                 End,
  1124.                 Child, HVSpace,
  1125.               End,
  1126.               Child, VGroup,
  1127.                 Child, HVSpace,
  1128.                 Child, HGroup,
  1129.                   Child, HSpace(0),
  1130.                   Child, ColGroup(2),
  1131.                     GroupFrameT(GetMessage(MSG_PRIMARY_CONTROLLER)),
  1132.                     MUIA_HorizWeight, 1000,
  1133.                     Child, Label(GetMessage(MSG_TYPE)),
  1134.                     Child, CY_Joy1Type = CycleObject,
  1135.                       MUIA_Cycle_Entries, (ULONG) Joy1Types,
  1136.                     End,
  1137.                     Child, Label(GetMessage(MSG_BUTTON_B_HOLD_TIME)),
  1138.                     Child, SL_Joy1ButtonBTime = SliderObject,
  1139.                       MUIA_Slider_Min,    0,
  1140.                       MUIA_Slider_Max,    9,
  1141.                     End,
  1142.                     Child, Label(GetMessage(MSG_AUTO_FIRE_RATE)),
  1143.                     Child, SL_Joy1AutoFireRate = SliderObject,
  1144.                       MUIA_Slider_Min,    0,
  1145.                       MUIA_Slider_Max,    5,
  1146.                     End,
  1147.                   End,
  1148.                   Child, HSpace(0),
  1149.                 End,
  1150.                 Child, HGroup,
  1151.                   Child, HSpace(0),
  1152.                   Child, ColGroup(2),
  1153.                     GroupFrameT(GetMessage(MSG_SECONDARY_CONTROLLER)),
  1154.                     MUIA_HorizWeight, 1000,
  1155.                     Child, Label(GetMessage(MSG_TYPE)),
  1156.                     Child, CY_Joy2Type = CycleObject,
  1157.                       MUIA_Cycle_Entries, (ULONG) Joy2Types,
  1158.                     End,
  1159.                     Child, Label(GetMessage(MSG_BUTTON_B_HOLD_TIME)),
  1160.                     Child, SL_Joy2ButtonBTime = SliderObject,
  1161.                       MUIA_Slider_Min,    0,
  1162.                       MUIA_Slider_Max,    9,
  1163.                     End,
  1164.                     Child, Label(GetMessage(MSG_AUTO_FIRE_RATE)),
  1165.                     Child, SL_Joy2AutoFireRate = SliderObject,
  1166.                       MUIA_Slider_Min,    0,
  1167.                       MUIA_Slider_Max,    5,
  1168.                     End,
  1169.                   End,
  1170.                   Child, HSpace(0),
  1171.                 End,
  1172.                 Child, HVSpace,
  1173.               End,
  1174.               Child, VGroup,
  1175.                 Child, HVSpace,
  1176.                 Child, HGroup,
  1177.                   Child, HSpace(0),
  1178.                   Child, ColGroup(2),
  1179.                     MUIA_HorizWeight, 1000,
  1180.                     Child, Label(GetMessage(MSG_ROM_PATH)),
  1181.                     Child, PA_RomPath = PopaslObject,
  1182.                       MUIA_Popstring_String,  ST_RomPath = String(0, 256),
  1183.                       MUIA_Popstring_Button,  PopButton(MUII_PopDrawer),
  1184.                       ASLFR_DrawersOnly,    TRUE,
  1185.                     End,
  1186.                     Child, Label(GetMessage(MSG_SAMPLE_PATH)),
  1187.                     Child, PA_SamplePath = PopaslObject,
  1188.                       MUIA_Popstring_String,  ST_SamplePath = String(0, 256),
  1189.                       MUIA_Popstring_Button,  PopButton(MUII_PopDrawer),
  1190.                       ASLFR_DrawersOnly,    TRUE,
  1191.                     End,
  1192.                   End,
  1193.                   Child, HSpace(0),
  1194.                 End,
  1195.                 Child, HVSpace,
  1196.               End,
  1197.             End,
  1198.             Child, HGroup,
  1199.               Child, BU_Start   = SimpleButton(GetMessage(MSG_START)),
  1200.               Child, BU_Quit    = SimpleButton(GetMessage(MSG_QUIT)),
  1201.             End,
  1202.           End,
  1203.         End;
  1204.  
  1205.         if(MainWin)
  1206.         {
  1207.           DoMethod(App, OM_ADDMEMBER, MainWin);
  1208.  
  1209.           DoMethod(LV_Driver, MUIM_Notify,  MUIA_Listview_DoubleClick, TRUE,
  1210.                    App, 2, MUIM_Application_ReturnID,  RID_Start);
  1211.                    
  1212.           DoMethod(BU_Start, MUIM_Notify, MUIA_Pressed, FALSE,
  1213.                    App, 2, MUIM_Application_ReturnID, RID_Start);
  1214.  
  1215.           DoMethod(BU_Quit, MUIM_Notify, MUIA_Pressed, FALSE,
  1216.                    App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  1217.  
  1218.           DoMethod(MainWin, MUIM_Notify,  MUIA_Window_CloseRequest, TRUE,
  1219.                    App, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
  1220.  
  1221.           DoMethod(CM_AutoFrameSkip, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  1222.                    SL_FrameSkip, 3, MUIM_Set, MUIA_Disabled, MUIV_TriggerValue);
  1223.  
  1224.           DoMethod(SL_Joy1AutoFireRate, MUIM_Notify, MUIA_Slider_Level, MUIV_EveryTime,
  1225.                    SL_Joy1ButtonBTime, 3, MUIM_Set, MUIA_Disabled, MUIV_TriggerValue);
  1226.  
  1227.           DoMethod(SL_Joy2AutoFireRate, MUIM_Notify, MUIA_Slider_Level, MUIV_EveryTime,
  1228.                    SL_Joy2ButtonBTime, 3, MUIM_Set, MUIA_Disabled, MUIV_TriggerValue);
  1229.  
  1230.           DoMethod(MainWin, MUIM_Notify, MUIA_Window_MenuAction, MUIV_EveryTime,
  1231.                    App, 2, MUIM_Application_ReturnID, MUIV_TriggerValue);
  1232.  
  1233.           DoMethod(CY_ScreenType, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
  1234.                    CY_ScreenType, 3, MUIM_CallHook, &ScreenTypeNotifyHook,  MUIV_TriggerValue);
  1235.  
  1236.           DoMethod(CY_DirectMode, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
  1237.                    CY_DirectMode, 3, MUIM_CallHook, &DirectModeNotifyHook, MUIV_TriggerValue);
  1238.  
  1239.           DoMethod(CY_Sound, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
  1240.                    CY_Sound, 3, MUIM_CallHook, &SoundNotifyHook, MUIV_TriggerValue);
  1241.  
  1242.           DoMethod(LI_Driver, MUIM_Notify, MUIA_List_Active, MUIV_EveryTime,
  1243.                    LI_Driver, 3, MUIM_CallHook, &DriverNotifyHook, MUIV_TriggerValue);
  1244. #ifndef MESS
  1245.           DoMethod(CY_Show, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
  1246.                    CY_Show, 3, MUIM_CallHook, &ShowNotifyHook, MUIV_TriggerValue);
  1247.  
  1248.           DoMethod(CM_UseDefaults, MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
  1249.                    CM_UseDefaults, 3, MUIM_CallHook, &UseDefaultsNotifyHook, MUIV_TriggerValue);
  1250.  
  1251.           DoMethod(BU_Scan, MUIM_Notify, MUIA_Pressed, FALSE,
  1252.                    App, 2, MUIM_Application_ReturnID, RID_Scan);
  1253. #endif
  1254.           DoMethod(MainWin,  MUIM_Window_SetCycleChain,  LV_Driver,
  1255. #ifndef MESS
  1256.                    CM_UseDefaults, CY_Show, BU_Scan,
  1257. #endif
  1258.                    BU_Start, BU_Quit, CM_Allow16Bit, CM_FlipX, CM_FlipY, CM_DirtyLines, CM_AutoFrameSkip,
  1259.                    CM_Antialiasing, CM_Translucency, SL_BeamWidth, SL_VectorFlicker, SL_FrameSkip,
  1260.                    ST_Width, ST_Height, CY_ScreenType, CY_DirectMode, CY_Buffering, CY_Rotation,
  1261.                    PU_ScreenMode, CY_Sound, SL_AudioChannel[0], SL_AudioChannel[1], SL_AudioChannel[2],
  1262.                    SL_AudioChannel[3], SL_MinFreeChip, CY_Joy1Type, SL_Joy1ButtonBTime, SL_Joy1AutoFireRate,
  1263.                    CY_Joy2Type, SL_Joy2ButtonBTime, SL_Joy2AutoFireRate, ST_RomPath, PA_RomPath,
  1264.                    ST_SamplePath, PA_SamplePath, RE_Options, NULL);
  1265.  
  1266. #ifdef MESS
  1267.           DoMethod(LI_Driver, MUIM_List_Insert, SortedDrivers, NumDrivers + DRIVER_OFFSET, MUIV_List_Insert_Bottom);
  1268. #else
  1269.           ShowNotify(NULL, NULL, &Config[CFG_SHOW]);
  1270. #endif
  1271.         }
  1272.       }
  1273.  
  1274.       if(MainWin)
  1275.       {
  1276.         SetOptions(TRUE);
  1277.  
  1278.         set(MainWin,  MUIA_Window_ActiveObject, (ULONG) LV_Driver);
  1279.         set(MainWin,  MUIA_Window_Open,     TRUE);
  1280.  
  1281.         /* This must be done after the window has been opened. */
  1282.  
  1283.         DoMethod( LI_Driver, MUIM_List_Jump, MUIV_List_Jump_Active);
  1284.  
  1285.         do
  1286.         {
  1287.           rid = DoMethod(App,MUIM_Application_NewInput,&signals);
  1288.  
  1289.           switch(rid)
  1290.           {
  1291.             case RID_Start:
  1292.               get(LI_Driver, MUIA_List_Active, &v);
  1293.  
  1294.               if(v != MUIV_List_Active_Off)
  1295.               {
  1296.                 GetOptions(TRUE);
  1297.  
  1298.                 if(Config[CFG_DRIVER] >= 0)
  1299.                   loop = FALSE;
  1300.               }
  1301.  
  1302.               break;
  1303. #ifndef MESS
  1304.             case RID_Scan:
  1305.               GetOptions(FALSE);
  1306.  
  1307.               DoMethod(LI_Driver, MUIM_List_Clear);
  1308.  
  1309.               ScanDrivers();
  1310.               ShowFound();
  1311.  
  1312.               break;
  1313. #endif
  1314.             case MUIV_Application_ReturnID_Quit:
  1315.               GetOptions(TRUE);
  1316.  
  1317.               loop = FALSE;
  1318.  
  1319.               break;
  1320.  
  1321.             case MID_About:
  1322.               set(AboutWin, MUIA_Window_Open, TRUE);
  1323.  
  1324.               break;
  1325.  
  1326.             case RID_CloseAbout:
  1327.               set(AboutWin, MUIA_Window_Open, FALSE);
  1328.  
  1329.               break;
  1330.  
  1331.             case MID_AboutMUI:
  1332.               DoMethod(App, MUIM_Application_AboutMUI,  MainWin);
  1333.  
  1334.               break;
  1335.           }
  1336.  
  1337.           if(signals && loop)
  1338.           {
  1339.             signals = Wait(signals | SIGBREAKF_CTRL_C);
  1340.  
  1341.             if(signals & SIGBREAKF_CTRL_C)
  1342.               loop = FALSE;
  1343.           }
  1344.         } while(loop);
  1345.  
  1346.         set(AboutWin, MUIA_Window_Open, FALSE);
  1347.         set(MainWin,  MUIA_Window_Open, FALSE);
  1348.  
  1349.         if(rid == RID_Start)
  1350.           return(0);
  1351.       }
  1352.     }
  1353.   }
  1354.   return(1);
  1355. };
  1356.  
  1357. void AboutGUI(void)
  1358. {
  1359.   ULONG signals = 0;
  1360.  
  1361.   if(MUIMasterBase)
  1362.   {
  1363.     if(!App)
  1364.       CreateApp();
  1365.     if(App)
  1366.     {
  1367.       set(AboutWin, MUIA_Window_ActiveObject, (ULONG) BU_About_OK);
  1368.       set(AboutWin, MUIA_Window_Open, TRUE);
  1369.  
  1370.       for(;DoMethod(App, MUIM_Application_NewInput, &signals) != RID_CloseAbout;)
  1371.       {
  1372.         if(signals)
  1373.         {
  1374.           if(Inputs)
  1375.             signals = Wait(signals|SIGBREAKF_CTRL_C|Inputs->SignalMask);
  1376.           else
  1377.             signals = Wait(signals|SIGBREAKF_CTRL_C);
  1378.  
  1379.           if((signals & SIGBREAKF_CTRL_C))
  1380.             break;
  1381.  
  1382.           if(signals & Inputs->SignalMask)
  1383.             IUpdate(Inputs);
  1384.         }
  1385.       }
  1386.  
  1387.       set(AboutWin, MUIA_Window_Open, FALSE);
  1388.     }
  1389.   }
  1390. }
  1391.  
  1392. static void CreateApp(void)
  1393. {
  1394.   App = ApplicationObject,
  1395.     MUIA_Application_Title      , APPNAME,
  1396.     MUIA_Application_Version    , "$VER: "APPNAME" ("REVDATE")",
  1397.     MUIA_Application_Author     , AUTHOR,
  1398.     MUIA_Application_Base       , "MAME",
  1399.     SubWindow, AboutWin = WindowObject,
  1400.       MUIA_Window_Title, APPNAME,
  1401.       MUIA_Window_ID   , MAKE_ID('A','B','O','U'),
  1402.       WindowContents, VGroup,
  1403.         Child, ScrollgroupObject,
  1404.           MUIA_Scrollgroup_FreeHoriz, FALSE,
  1405.           MUIA_Scrollgroup_FreeVert, TRUE,
  1406.           MUIA_Scrollgroup_Contents, VirtgroupObject,
  1407.             VirtualFrame,
  1408.             MUIA_Background, MUII_TextBack,
  1409.             Child, VGroup,
  1410.               Child, TextObject,
  1411.                 MUIA_Text_Contents, TEXT_ABOUT,
  1412.               End,
  1413.               Child, VSpace(0),
  1414.             End,
  1415.           End,
  1416.           End,
  1417.         Child, HCenter(BU_About_OK = SimpleButton("_OK")),
  1418.       End,
  1419.     End,
  1420.   End;
  1421.  
  1422.   if(App)
  1423.   {
  1424.     DoMethod(BU_About_OK, MUIM_Notify, MUIA_Pressed, FALSE,
  1425.              App, 2, MUIM_Application_ReturnID, RID_CloseAbout);
  1426.  
  1427.     DoMethod(AboutWin, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
  1428.              App, 2, MUIM_Application_ReturnID, RID_CloseAbout);
  1429.   }
  1430. }
  1431.  
  1432. static void GetOptions(BOOL get_driver)
  1433. {
  1434.   int config_index;
  1435.  
  1436.   get(CY_ScreenType,       MUIA_Cycle_Active,    &Config[CFG_SCREENTYPE]);
  1437.   get(CY_DirectMode,       MUIA_Cycle_Active,    &Config[CFG_DIRECTMODE]);
  1438.   get(CM_DirtyLines,       MUIA_Selected,        &Config[CFG_DIRTYLINES]);
  1439.   get(CM_Allow16Bit,       MUIA_Selected,        &Config[CFG_ALLOW16BIT]);
  1440.   get(CM_FlipX,            MUIA_Selected,        &Config[CFG_FLIPX]);
  1441.   get(CM_FlipY,            MUIA_Selected,        &Config[CFG_FLIPY]);
  1442. #ifndef MESS
  1443.   get(CY_Show,             MUIA_Cycle_Active,    &Config[CFG_SHOW]);
  1444.   get(CM_UseDefaults,      MUIA_Selected,        &Config[CFG_USEDEFAULTS]);
  1445. #endif
  1446.   get(CM_Antialiasing,     MUIA_Selected,        &Config[CFG_ANTIALIASING]);
  1447.   get(CM_Translucency,     MUIA_Selected,        &Config[CFG_TRANSLUCENCY]);
  1448.   get(CM_AutoFrameSkip,    MUIA_Selected,        &Config[CFG_AUTOFRAMESKIP]);
  1449.   get(SL_BeamWidth,        MUIA_Slider_Level,    &Config[CFG_BEAMWIDTH]);
  1450.   get(SL_VectorFlicker,    MUIA_Slider_Level,    &Config[CFG_VECTORFLICKER]);
  1451.   get(SL_FrameSkip,        MUIA_Slider_Level,    &Config[CFG_FRAMESKIP]);
  1452.   get(ST_Width,            MUIA_String_Integer,  &Config[CFG_WIDTH]);
  1453.   get(ST_Height,           MUIA_String_Integer,  &Config[CFG_HEIGHT]);
  1454.   get(CY_Buffering,        MUIA_Cycle_Active,    &Config[CFG_BUFFERING]);
  1455.   get(CY_Rotation,         MUIA_Cycle_Active,    &Config[CFG_ROTATION]);
  1456.   get(CY_Sound,            MUIA_Cycle_Active,    &Config[CFG_SOUND]);
  1457.   get(SL_AudioChannel[0],  MUIA_Slider_Level,    &Config[CFG_AUDIOCHANNEL0]);
  1458.   get(SL_AudioChannel[1],  MUIA_Slider_Level,    &Config[CFG_AUDIOCHANNEL1]);
  1459.   get(SL_AudioChannel[2],  MUIA_Slider_Level,    &Config[CFG_AUDIOCHANNEL2]);
  1460.   get(SL_AudioChannel[3],  MUIA_Slider_Level,    &Config[CFG_AUDIOCHANNEL3]);
  1461.   get(SL_MinFreeChip,      MUIA_Slider_Level,    &Config[CFG_MINFREECHIP]);
  1462.   get(CY_Joy1Type,         MUIA_Cycle_Active,    &Config[CFG_JOY1TYPE]);
  1463.   get(SL_Joy1ButtonBTime,  MUIA_Slider_Level,    &Config[CFG_JOY1BUTTONBTIME]);
  1464.   get(SL_Joy1AutoFireRate, MUIA_Slider_Level,    &Config[CFG_JOY1AUTOFIRERATE]);
  1465.   get(CY_Joy2Type,         MUIA_Cycle_Active,    &Config[CFG_JOY2TYPE]);
  1466.   get(SL_Joy2ButtonBTime,  MUIA_Slider_Level,    &Config[CFG_JOY2BUTTONBTIME]);
  1467.   get(SL_Joy2AutoFireRate, MUIA_Slider_Level,    &Config[CFG_JOY2AUTOFIRERATE]);
  1468.   get(ST_RomPath,          MUIA_String_Contents, &Config[CFG_ROMPATH]);
  1469.   get(ST_SamplePath,       MUIA_String_Contents, &Config[CFG_SAMPLEPATH]);
  1470. #ifdef POWERUP
  1471.   get(CM_AsyncPPC,         MUIA_Selected,        &Config[CFG_ASYNCPPC]);
  1472. #endif
  1473.  
  1474.   Config[CFG_SCREENMODE] = ScreenModeTags[SMT_DISPLAYID].ti_Data;
  1475.   Config[CFG_DEPTH]      = ScreenModeTags[SMT_DEPTH].ti_Data;
  1476.  
  1477.   if(get_driver)
  1478.     Config[CFG_DRIVER] = GetDriverIndex();
  1479.  
  1480.   config_index = DRIVER_OFFSET + ((LONG) Config[CFG_DRIVER]);
  1481.  
  1482.   if(config_index >= 0)
  1483.     SetConfig(config_index, Config);
  1484. }
  1485.  
  1486. static void SetOptions(BOOL set_driver)
  1487. {
  1488.   ULONG i, v;
  1489.  
  1490.   GetConfig(Config[CFG_DRIVER] + DRIVER_OFFSET, Config);
  1491.  
  1492. #ifndef MESS
  1493.   if(Config[CFG_DRIVER] < 0)
  1494.     Config[CFG_USEDEFAULTS] = FALSE;
  1495.  
  1496.   set(CY_Show,             MUIA_Cycle_Active,    Config[CFG_SHOW]);
  1497.   set(CM_UseDefaults,      MUIA_Selected,        Config[CFG_USEDEFAULTS]);
  1498. #endif
  1499.   set(CY_ScreenType,       MUIA_Cycle_Active,    Config[CFG_SCREENTYPE]);
  1500.   set(CY_DirectMode,       MUIA_Cycle_Active,    Config[CFG_DIRECTMODE]);
  1501.   set(CM_DirtyLines,       MUIA_Selected,        Config[CFG_DIRTYLINES]);
  1502.   set(CM_Allow16Bit,       MUIA_Selected,        Config[CFG_ALLOW16BIT]);
  1503.   set(CM_FlipX,            MUIA_Selected,        Config[CFG_FLIPX]);
  1504.   set(CM_FlipY,            MUIA_Selected,        Config[CFG_FLIPY]);
  1505.   set(CM_Antialiasing,     MUIA_Selected,        Config[CFG_ANTIALIASING]);
  1506.   set(CM_Translucency,     MUIA_Selected,        Config[CFG_TRANSLUCENCY]);
  1507.   set(CM_AutoFrameSkip,    MUIA_Selected,        Config[CFG_AUTOFRAMESKIP]);
  1508.   set(SL_BeamWidth,        MUIA_Slider_Level,    Config[CFG_BEAMWIDTH]);
  1509.   set(SL_VectorFlicker,    MUIA_Slider_Level,    Config[CFG_VECTORFLICKER]);
  1510.   set(SL_FrameSkip,        MUIA_Slider_Level,    Config[CFG_FRAMESKIP]);
  1511.   set(ST_Width,            MUIA_String_Integer,  Config[CFG_WIDTH]);
  1512.   set(ST_Height,           MUIA_String_Integer,  Config[CFG_HEIGHT]);
  1513.   set(CY_Buffering,        MUIA_Cycle_Active,    Config[CFG_BUFFERING]);
  1514.   set(CY_Rotation,         MUIA_Cycle_Active,    Config[CFG_ROTATION]);
  1515.   set(CY_Sound,            MUIA_Cycle_Active,    Config[CFG_SOUND]);
  1516.   set(SL_AudioChannel[0],  MUIA_Slider_Level,    Config[CFG_AUDIOCHANNEL0]);
  1517.   set(SL_AudioChannel[1],  MUIA_Slider_Level,    Config[CFG_AUDIOCHANNEL1]);
  1518.   set(SL_AudioChannel[2],  MUIA_Slider_Level,    Config[CFG_AUDIOCHANNEL2]);
  1519.   set(SL_AudioChannel[3],  MUIA_Slider_Level,    Config[CFG_AUDIOCHANNEL3]);
  1520.   set(SL_MinFreeChip,      MUIA_Slider_Level,    Config[CFG_MINFREECHIP]);
  1521.   set(CY_Joy1Type,         MUIA_Cycle_Active,    Config[CFG_JOY1TYPE]);
  1522.   set(SL_Joy1ButtonBTime,  MUIA_Slider_Level,    Config[CFG_JOY1BUTTONBTIME]);
  1523.   set(SL_Joy1AutoFireRate, MUIA_Slider_Level,    Config[CFG_JOY1AUTOFIRERATE]);
  1524.   set(CY_Joy2Type,         MUIA_Cycle_Active,    Config[CFG_JOY2TYPE]);
  1525.   set(SL_Joy2ButtonBTime,  MUIA_Slider_Level,    Config[CFG_JOY2BUTTONBTIME]);
  1526.   set(SL_Joy2AutoFireRate, MUIA_Slider_Level,    Config[CFG_JOY2AUTOFIRERATE]);
  1527.   set(ST_RomPath,          MUIA_String_Contents, Config[CFG_ROMPATH]);
  1528.   set(ST_SamplePath,       MUIA_String_Contents, Config[CFG_SAMPLEPATH]);
  1529. #ifdef POWERUP
  1530.   set(CM_AsyncPPC,         MUIA_Selected,        Config[CFG_ASYNCPPC]);
  1531. #endif
  1532.  
  1533.   ScreenModeTags[SMT_DISPLAYID].ti_Data = Config[CFG_SCREENMODE];
  1534.   ScreenModeTags[SMT_DEPTH].ti_Data     = Config[CFG_DEPTH];
  1535.  
  1536.   SetDisplayName(Config[CFG_SCREENMODE]);
  1537.  
  1538.   if((Config[CFG_DRIVER] < 0) || (!Config[CFG_USEDEFAULTS]
  1539.      && (Drivers[Config[CFG_DRIVER]]->drv->video_attributes & VIDEO_SUPPORTS_16BIT)))
  1540.   {
  1541.     set(CM_Allow16Bit, MUIA_Disabled, FALSE);
  1542.   }
  1543.   else
  1544.     set(CM_Allow16Bit, MUIA_Disabled, TRUE);
  1545.  
  1546.   if(set_driver)
  1547.   {
  1548. #ifdef MESS
  1549.     if(Config[CFG_DRIVER] < 0)
  1550.       Config[CFG_DRIVER] = 0;
  1551.  
  1552.     for(i = 0; ; i++)
  1553. #else
  1554.     if(Config[CFG_DRIVER] == -2)
  1555.       set(LI_Driver,  MUIA_List_Active, 0);
  1556.     else if(Config[CFG_DRIVER] == -1)
  1557.       set(LI_Driver,  MUIA_List_Active, 1);
  1558.     else
  1559.     {
  1560.       for(i = 2; ; i++)
  1561. #endif
  1562.       {
  1563.         DoMethod(LI_Driver, MUIM_List_GetEntry, i, &v);
  1564.  
  1565.         if(!v)
  1566.           break;
  1567.  
  1568.         if(v == (ULONG) &Drivers[Config[CFG_DRIVER]])
  1569.         {
  1570.           set(LI_Driver,  MUIA_List_Active, i);
  1571.           break;
  1572.         }
  1573.       }
  1574. #ifndef MESS
  1575.     }
  1576. #endif
  1577.   }
  1578. }
  1579.  
  1580. static void SetDisplayName(ULONG displayid)
  1581. {
  1582.   LONG i, v;
  1583.  
  1584.   i = 0;
  1585.   v = GetDisplayInfoData(NULL, (UBYTE *) &DisplayNameInfo, sizeof(DisplayNameInfo),
  1586.                          DTAG_NAME, displayid);
  1587.  
  1588.   if(v > sizeof(struct QueryHeader))
  1589.     {
  1590.     for(; (i < sizeof(DisplayNameBuffer) - 1) && DisplayNameInfo.Name[i]; i++)
  1591.       DisplayNameBuffer[i]  = DisplayNameInfo.Name[i];
  1592.   }
  1593.  
  1594.   if(displayid == INVALID_ID)
  1595.     strcpy(DisplayNameBuffer, GetMessage(MSG_INVALID));
  1596.   else
  1597.   {
  1598.     if(i < sizeof(DisplayNameBuffer) - sizeof(" (0x00000000)"))
  1599.     {
  1600.       DisplayNameBuffer[i++]  = ' ';
  1601.       DisplayNameBuffer[i++]  = '(';
  1602.       DisplayNameBuffer[i++]  = '0';
  1603.       DisplayNameBuffer[i++]  = 'x';
  1604.  
  1605.       for(v = 28; (v >= 0) && (!((displayid >> v) & 0xf)); v -= 4);
  1606.  
  1607.       if(v < 0)
  1608.         DisplayNameBuffer[i++]  = '0';
  1609.  
  1610.       for(; (v >= 0); v -= 4)
  1611.       {
  1612.         if(((displayid >> v) & 0xf) > 9)
  1613.           DisplayNameBuffer[i++]  = ((displayid >> v) & 0xf) + 'a' - 10;
  1614.         else
  1615.           DisplayNameBuffer[i++]  = ((displayid >> v) & 0xf) + '0';
  1616.       }
  1617.       DisplayNameBuffer[i++]  = ')';
  1618.     }
  1619.  
  1620.     DisplayNameBuffer[i++]  = 0;
  1621.   }
  1622.  
  1623.   set(DisplayName, MUIA_Text_Contents, (ULONG) DisplayNameBuffer);
  1624. }
  1625.  
  1626. static ULONG ASM ScreenModeStart(struct Hook *hook REG(a0), APTR popasl REG(a2), struct TagItem *taglist REG(a1))
  1627. {
  1628.   LONG  i;
  1629.  
  1630.   for(i = 0; taglist[i].ti_Tag != TAG_END; i++);
  1631.  
  1632.   taglist[i].ti_Tag = TAG_MORE;
  1633.   taglist[i].ti_Data  = (ULONG) ScreenModeTags;
  1634.  
  1635.   return(TRUE);
  1636. }
  1637.  
  1638. static ULONG ASM ScreenModeStop(struct Hook *hook REG(a0), APTR popasl REG(a2), struct ScreenModeRequester *smreq REG(a1))
  1639. {
  1640.   ScreenModeTags[SMT_DISPLAYID].ti_Data = smreq->sm_DisplayID;
  1641.   ScreenModeTags[SMT_DEPTH].ti_Data   = smreq->sm_DisplayDepth;
  1642.  
  1643.   SetDisplayName(smreq->sm_DisplayID);
  1644.  
  1645.   return(0);
  1646. }
  1647.  
  1648. #ifndef MESS
  1649. static ULONG ASM ShowNotify(struct Hook *hook REG(a0), APTR obj REG(a2), ULONG *par REG(a1))
  1650. {
  1651.   DoMethod(LI_Driver, MUIM_List_Clear);
  1652.  
  1653.   switch(*par)
  1654.   {
  1655.     case CFGS_ALL:
  1656.       set(BU_Scan, MUIA_Disabled, TRUE);
  1657.       DoMethod(LI_Driver, MUIM_List_Insert, SortedDrivers, NumDrivers + DRIVER_OFFSET, MUIV_List_Insert_Bottom);
  1658.       break;
  1659.       
  1660.     case CFGS_FOUND:
  1661.       set(BU_Scan, MUIA_Disabled, FALSE);
  1662.       ShowFound();
  1663.       break;
  1664.   }
  1665.   
  1666.   return(0);
  1667. }
  1668. #endif
  1669.  
  1670. static ULONG ASM ScreenTypeNotify(struct Hook *hook REG(a0), APTR obj REG(a2), ULONG *par REG(a1))
  1671. {
  1672.   if(*par == CFGST_CUSTOM)
  1673.   {
  1674.     set(PA_ScreenMode,  MUIA_Disabled, FALSE);
  1675.     set(PU_ScreenMode,  MUIA_Disabled, FALSE);
  1676.   }
  1677.   else
  1678.   {
  1679.     set(PA_ScreenMode,  MUIA_Disabled, TRUE);
  1680.     set(PU_ScreenMode,  MUIA_Disabled, TRUE);
  1681.   }
  1682.  
  1683.   return(0);
  1684. }
  1685.  
  1686. static ULONG ASM DirectModeNotify(struct Hook *hook REG(a0), APTR obj REG(a2), ULONG *par REG(a1))
  1687. {
  1688.   if(*par == CFGDM_DRAW)
  1689.     set(CM_DirtyLines, MUIA_Disabled, TRUE);
  1690.   else
  1691.     set(CM_DirtyLines, MUIA_Disabled, FALSE);
  1692.  
  1693.   return(0);
  1694. }
  1695.  
  1696. static ULONG ASM SoundNotify(struct Hook *hook REG(a0), APTR obj REG(a2), ULONG *par REG(a1))
  1697. {
  1698.   switch(*par)
  1699.   {
  1700.     case 1:
  1701.       set(SL_AudioChannel[0], MUIA_Disabled, FALSE);
  1702.       set(SL_AudioChannel[1], MUIA_Disabled, FALSE);
  1703.       set(SL_AudioChannel[2], MUIA_Disabled, FALSE);
  1704.       set(SL_AudioChannel[3], MUIA_Disabled, FALSE);
  1705.       set(SL_MinFreeChip, MUIA_Disabled, FALSE);
  1706.       break;
  1707.     default:
  1708.       set(SL_AudioChannel[0], MUIA_Disabled, TRUE);
  1709.       set(SL_AudioChannel[1], MUIA_Disabled, TRUE);
  1710.       set(SL_AudioChannel[2], MUIA_Disabled, TRUE);
  1711.       set(SL_AudioChannel[3], MUIA_Disabled, TRUE);
  1712.       set(SL_MinFreeChip, MUIA_Disabled, TRUE);
  1713.       break;
  1714.   }
  1715.  
  1716.   return(0);
  1717. }
  1718.  
  1719. static ULONG ASM DriverNotify(struct Hook *hook REG(a0), APTR obj REG(a2), ULONG *par REG(a1))
  1720. {
  1721.   GetOptions(FALSE);
  1722.  
  1723.   if(*par < DRIVER_OFFSET)
  1724.   {
  1725.     set(CM_UseDefaults, MUIA_Disabled, TRUE);
  1726.     set(CM_Allow16Bit,  MUIA_Disabled, FALSE);
  1727.   }
  1728.   else
  1729.   {
  1730.     set(CM_UseDefaults, MUIA_Disabled, FALSE);
  1731.   }
  1732.  
  1733.   Config[CFG_DRIVER] = GetDriverIndex();
  1734.  
  1735.   SetOptions(FALSE);
  1736.   
  1737.   return(0);
  1738. }
  1739.  
  1740. #ifndef MESS
  1741. static ULONG ASM UseDefaultsNotify(struct Hook *hook REG(a0), APTR obj REG(a2), ULONG *par REG(a1))
  1742. {
  1743.   struct GameDriver *drv;
  1744.  
  1745.   ULONG v;
  1746.  
  1747.   if(*par)
  1748.   {
  1749.     set(CY_ScreenType,       MUIA_Disabled, TRUE);
  1750.     set(CY_DirectMode,       MUIA_Disabled, TRUE);
  1751.     set(CM_Allow16Bit,       MUIA_Disabled, TRUE);
  1752.     set(CM_FlipX,            MUIA_Disabled, TRUE);
  1753.     set(CM_FlipY,            MUIA_Disabled, TRUE);
  1754.     set(CM_Antialiasing,     MUIA_Disabled, TRUE);
  1755.     set(CM_Translucency,     MUIA_Disabled, TRUE);
  1756.     set(CM_AutoFrameSkip,    MUIA_Disabled, TRUE);
  1757.     set(SL_BeamWidth,        MUIA_Disabled, TRUE);
  1758.     set(SL_VectorFlicker,    MUIA_Disabled, TRUE);
  1759.     set(SL_FrameSkip,        MUIA_Disabled, TRUE);
  1760.     set(ST_Width,            MUIA_Disabled, TRUE);
  1761.     set(ST_Height,           MUIA_Disabled, TRUE);
  1762.     set(CY_Buffering,        MUIA_Disabled, TRUE);
  1763.     set(CY_Rotation,         MUIA_Disabled, TRUE);
  1764.     set(CY_Sound,            MUIA_Disabled, TRUE);
  1765.     set(SL_MinFreeChip,      MUIA_Disabled, TRUE);
  1766.     set(CY_Joy1Type,         MUIA_Disabled, TRUE);
  1767.     set(SL_Joy1ButtonBTime,  MUIA_Disabled, TRUE);
  1768.     set(SL_Joy1AutoFireRate, MUIA_Disabled, TRUE);
  1769.     set(CY_Joy2Type,         MUIA_Disabled, TRUE);
  1770.     set(SL_Joy2ButtonBTime,  MUIA_Disabled, TRUE);
  1771.     set(SL_Joy2AutoFireRate, MUIA_Disabled, TRUE);
  1772.     set(ST_RomPath,          MUIA_Disabled, TRUE);
  1773.     set(ST_SamplePath,       MUIA_Disabled, TRUE);
  1774.     set(PA_RomPath,          MUIA_Disabled, TRUE);
  1775.     set(PA_SamplePath,       MUIA_Disabled, TRUE);
  1776.     set(CM_DirtyLines,       MUIA_Disabled, TRUE);
  1777.     set(PU_ScreenMode,       MUIA_Disabled, TRUE);
  1778.     set(PA_ScreenMode,       MUIA_Disabled, TRUE);
  1779.     set(SL_AudioChannel[0],  MUIA_Disabled, TRUE);
  1780.     set(SL_AudioChannel[1],  MUIA_Disabled, TRUE);
  1781.     set(SL_AudioChannel[2],  MUIA_Disabled, TRUE);
  1782.     set(SL_AudioChannel[3],  MUIA_Disabled, TRUE);
  1783. #ifdef POWERUP
  1784.     set(CM_AsyncPPC,         MUIA_Disabled, TRUE);
  1785. #endif
  1786.   }
  1787.   else
  1788.   {
  1789.     set(CY_ScreenType,       MUIA_Disabled, FALSE);
  1790.     set(CY_DirectMode,       MUIA_Disabled, FALSE);
  1791.     set(CM_FlipX,            MUIA_Disabled, FALSE);
  1792.     set(CM_FlipY,            MUIA_Disabled, FALSE);
  1793.     set(CM_Antialiasing,     MUIA_Disabled, FALSE);
  1794.     set(CM_Translucency,     MUIA_Disabled, FALSE);
  1795.     set(CM_AutoFrameSkip,    MUIA_Disabled, FALSE);
  1796.     set(SL_BeamWidth,        MUIA_Disabled, FALSE);
  1797.     set(SL_VectorFlicker,    MUIA_Disabled, FALSE);
  1798.     set(SL_FrameSkip,        MUIA_Disabled, FALSE);
  1799.     set(ST_Width,            MUIA_Disabled, FALSE);
  1800.     set(ST_Height,           MUIA_Disabled, FALSE);
  1801.     set(CY_Buffering,        MUIA_Disabled, FALSE);
  1802.     set(CY_Rotation,         MUIA_Disabled, FALSE);
  1803.     set(CY_Sound,            MUIA_Disabled, FALSE);
  1804.     set(SL_MinFreeChip,      MUIA_Disabled, FALSE);
  1805.     set(CY_Joy1Type,         MUIA_Disabled, FALSE);
  1806.     set(SL_Joy1ButtonBTime,  MUIA_Disabled, FALSE);
  1807.     set(SL_Joy1AutoFireRate, MUIA_Disabled, FALSE);
  1808.     set(CY_Joy2Type,         MUIA_Disabled, FALSE);
  1809.     set(SL_Joy2ButtonBTime,  MUIA_Disabled, FALSE);
  1810.     set(SL_Joy2AutoFireRate, MUIA_Disabled, FALSE);
  1811.     set(ST_RomPath,          MUIA_Disabled, FALSE);
  1812.     set(ST_SamplePath,       MUIA_Disabled, FALSE);
  1813.     set(PA_RomPath,          MUIA_Disabled, FALSE);
  1814.     set(PA_SamplePath,       MUIA_Disabled, FALSE);
  1815. #ifdef POWERUP
  1816.     set(CM_AsyncPPC,         MUIA_Disabled, FALSE);
  1817. #endif
  1818.  
  1819.     get(CY_ScreenType, MUIA_Cycle_Active, &v);
  1820.     ScreenTypeNotify(&ScreenTypeNotifyHook, CY_ScreenType, &v);
  1821.  
  1822.     get(CY_DirectMode, MUIA_Cycle_Active,  &v);
  1823.     DirectModeNotify(&DirectModeNotifyHook, CY_DirectMode, &v);
  1824.  
  1825.     get(CY_Sound, MUIA_Cycle_Active, &v);
  1826.     SoundNotify(&SoundNotifyHook, CY_Sound, &v);
  1827.  
  1828.     drv = GetDriver();
  1829.  
  1830.     if(!drv || (drv->drv->video_attributes & VIDEO_SUPPORTS_16BIT))
  1831.       set(CM_Allow16Bit, MUIA_Disabled, FALSE);
  1832.     else
  1833.       set(CM_Allow16Bit, MUIA_Disabled, TRUE);
  1834.   }
  1835.  
  1836.   return(0);
  1837. }
  1838. #endif
  1839.